package LeetCode.LC1160;

/**
 * @author corn
 * @create 2020-11-07-20:25
 */
public class Solution {
    public int countCharacters(String[] words, String chars) {
        int length = 0;
        int[] cArray = new int[26];
        for(char c : chars.toCharArray()){
            cArray[c - 'a']++;
        }
        for(String word : words){
            Boolean flag = true;
            int[] wArray = new int[26];
            for(char w : word.toCharArray()){
                wArray[w - 'a']++;
            }
            for(char w : word.toCharArray()){
                if( wArray[w - 'a'] > cArray[w - 'a']){
                    flag = false;
                }
            }
            if(flag == true){
                length += word.length();
            }
        }
        return length;
    }
}
